import matplotlib.pyplot as plt
import numpy as np
from PIL import Image, ImageDraw


# 从文本文件中读取矩阵
# pr = np.loadtxt("img_out/log.txt", dtype=int)

def paint_deeplab_res_img(pr):
    # 将0转换为黑色，1转换为白色
    pr_color = np.where(pr == 0, 0, 1)  # 将颜色值改为数值类型

    # 创建一个图像窗口
    plt.figure()
    #
    # 绘制图像
    plt.imshow(pr_color, cmap='gray', vmin=0, vmax=1)

    # 隐藏坐标轴
    plt.axis('off')

    # 显示图像
    plt.show()


def show_blend_img(pr):
    orininal_h = 640
    orininal_w = 640

    colors = [(0, 0, 0), (0, 100, 0)]

    seg_img = np.reshape(np.array(colors, np.uint8)[np.reshape(pr, [-1])], [orininal_h, orininal_w, -1])
    image = Image.fromarray(np.uint8(seg_img))
    old_img = Image.open("img_out/00.jpeg")
    image = Image.blend(old_img, image, 0.5)
    image.show()


def paint_zone():
    # Load the image
    image_path = 'img/0.jpeg'  # Replace with your image path
    image = Image.open(image_path)

    # Coordinates of the bounding box
    xmin = 0
    xmax = 50
    ymin = 100
    ymax = 272

    # Create a drawing object
    draw = ImageDraw.Draw(image)

    # Draw a rectangle on the image
    rectangle_coordinates = [(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax), (xmin, ymin)]
    draw.line(rectangle_coordinates, fill='red', width=2)

    # Save or display the image
    image.show()  # This will display the image with the rectangle
